@use '@material/theme/theme-color' as mdc-theme-color;
@use '@material/radio/radio-theme' as mdc-radio-theme;
@use '@material/radio/radio' as mdc-radio;
@use '@material/form-field' as mdc-form-field;
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/theming/theming';


@mixin color($config-or-theme) {
  $config: theming.get-color-config($config-or-theme);
  // Save original values of MDC global variables. We need to save these so we can restore the
  // variables to their original values and prevent unintended side effects from using this mixin.
  $orig-baseline-theme-color: mdc-radio-theme.$baseline-theme-color;
  $orig-unchecked-color: mdc-radio-theme.$unchecked-color;
  $orig-disabled-circle-color: mdc-radio-theme.$disabled-circle-color;

  @include mdc-helpers.mat-using-mdc-theme($config) {
    mdc-radio-theme.$baseline-theme-color: primary;
    mdc-radio-theme.$unchecked-color: rgba(mdc-theme-color.prop-value(on-surface), 0.54);
    mdc-radio-theme.$disabled-circle-color: rgba(mdc-theme-color.prop-value(on-surface), 0.38);

    .mat-mdc-radio-button {
      @include mdc-form-field.core-styles($query: mdc-helpers.$mat-theme-styles-query);

      &.mat-primary {
        @include mdc-radio.without-ripple($query: mdc-helpers.$mat-theme-styles-query);
      }

      &.mat-accent {
        mdc-radio-theme.$baseline-theme-color: secondary;
        @include mdc-radio.without-ripple($query: mdc-helpers.$mat-theme-styles-query);
      }

      &.mat-warn {
        mdc-radio-theme.$baseline-theme-color: error;
        @include mdc-radio.without-ripple($query: mdc-helpers.$mat-theme-styles-query);
      }
    }
  }

  // Restore original values of MDC global variables.
  mdc-radio-theme.$baseline-theme-color: $orig-baseline-theme-color;
  mdc-radio-theme.$unchecked-color: $orig-unchecked-color;
  mdc-radio-theme.$disabled-circle-color: $orig-disabled-circle-color;
}

@mixin typography($config-or-theme) {
  $config: theming.get-typography-config($config-or-theme);
  @include mdc-helpers.mat-using-mdc-typography($config) {
    @include mdc-radio.without-ripple($query: mdc-helpers.$mat-typography-styles-query);
    @include mdc-form-field.core-styles($query: mdc-helpers.$mat-typography-styles-query);
  }
}

@mixin density($config-or-theme) {
  $density-scale: theming.get-density-config($config-or-theme);
  .mat-mdc-radio-button .mdc-radio {
    @include mdc-radio-theme.density($density-scale, $query: mdc-helpers.$mat-base-styles-query);
  }
}

@mixin theme($theme-or-color-config) {
  $theme: theming.private-legacy-get-theme($theme-or-color-config);
  @include theming.private-check-duplicate-theme-styles($theme, 'mat-mdc-radio') {
    $color: theming.get-color-config($theme);
    $density: theming.get-density-config($theme);
    $typography: theming.get-typography-config($theme);

    @if $color != null {
      @include color($color);
    }
    @if $density != null {
      @include density($density);
    }
    @if $typography != null {
      @include typography($typography);
    }
  }
}
